<?php
require '../../common/initPage.php';
require '../../common/dbcon.php';
require '../../common/func.php';
require '../../common/showTips.php';

session_start();
//拦截未登录
filterLogout();

if (empty($_GET['show'])) {
    unset($_SESSION['actionMessShowTips']);
}

$longshowunread=queryUndealMess($mysqlCon, queryBrowseUnreadNum, $_SESSION['loginId']);
$longshowsave=queryBrowseNum($mysqlCon, queryBrowseSaveNum, $_SESSION['loginId'],'');
$longshowtrash=queryUndealMess($mysqlCon, queryBrowseTrashAllNum, $_SESSION['loginId']);

$_SESSION['checkCate']=$_GET['check'];
$recheckCate=$_SESSION['checkCate'];

$_SESSION['filter']=$_GET['filter'];
$refilter=$_SESSION['filter'];

$pageNow = $_GET['pagenow'];
$_SESSION['messagePageNow'] = $_GET['pagenow'];
$rempagenow = $_SESSION['messagePageNow'];

$searchValue = $_GET['searchvalue'];
$_SESSION['messageSearchvalue'] = $_GET['searchvalue'];
$remsearchvalue = $_SESSION['messageSearchvalue'];

$LCUI=queryLastConnectUserInfo($mysqlCon,queryLCU,$_SESSION['loginId']);

//所有消息
if(empty($_GET['check'])&&empty($_GET['filter'])){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseAllNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseAll,$_SESSION['loginId'],$searchValue,$pageNow);
}
if(empty($_GET['check'])&&$_GET['filter']=='read'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseAllButReadNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseAllButRead,$_SESSION['loginId'],$searchValue,$pageNow);
}
if(empty($_GET['check'])&&$_GET['filter']=='unread'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseAllButUnReadNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseAllButUnRead,$_SESSION['loginId'],$searchValue,$pageNow);
}

//收藏消息
if($_GET['check']=='star'&&empty($_GET['filter'])){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseSartNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseSart,$_SESSION['loginId'],$searchValue,$pageNow);
}
if($_GET['check']=='star'&&$_GET['filter']=='read'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseSartButReadNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseSartButRead,$_SESSION['loginId'],$searchValue,$pageNow);
}
if($_GET['check']=='star'&&$_GET['filter']=='unread'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseSartButUnReadNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseSartButUnRead,$_SESSION['loginId'],$searchValue,$pageNow);
}

//草稿消息
if($_GET['check']=='save'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseSaveNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseSave,$_SESSION['loginId'],$searchValue,$pageNow);
}

//已发送消息
if($_GET['check']=='send'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseSendNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseSend,$_SESSION['loginId'],$searchValue,$pageNow);
}

//回收站消息
if($_GET['check']=='trash'&&empty($_GET['filter'])){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseTrashNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseTrash,$_SESSION['loginId'],$searchValue,$pageNow);
}
if($_GET['check']=='trash'&&$_GET['filter']=='read'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseTrasButReadNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseTrashButRead,$_SESSION['loginId'],$searchValue,$pageNow);
}
if($_GET['check']=='trash'&&$_GET['filter']=='unread'){
    $ListTotal = queryBrowseNum($mysqlCon, queryBrowseTrashButUnReadNum, $_SESSION['loginId'],$searchValue);
    $pageTotal=pageFunc($ListTotal);
    $showResult=queryBrowse($mysqlCon,queryBrowseTrashButUnRead,$_SESSION['loginId'],$searchValue,$pageNow);
}

$routerUrl = '../../views/public/message.html';
if($_SESSION['loginIden']=='管理员'){
    require '../../views/admin/template.html';
}else{
    require '../../views/user/template.html';
}